package com.example.nio.service.Impl;

import cn.hutool.json.JSONUtil;
import com.example.nio.commons.Message;
import com.example.nio.service.MessageSendService;
import com.example.nio.util.BridgeUtil;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class MessageSendServiceImpl implements MessageSendService {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Value("${spring.rabbitmq.directexchange}")
    private String exchangeName;

    @Value("${spring.rabbitmq.directrouting}")
    private String routingName;

    @Override
    public void messageHandling(Message chatMessage) {
        try {
            //发布mq
            rabbitTemplate.convertAndSend(exchangeName, routingName, JSONUtil.toJsonStr(chatMessage));
            System.out.println("rabbitmq发送消息到转换器："+ exchangeName + "，路由："+ routingName + ",消息内容："+JSONUtil.toJsonStr(chatMessage));
            //wxService.getWxMessage(wxMessage);
        } catch (Exception e) {
            System.out.println("发送消息失败");
        }
    }


}
